<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8" />
	<title>千郡医疗-我的记录</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" th:href="@{/weixin/css/style.css}" />
	<link rel="stylesheet" th:href="@{/weixin/css/dropload.css}" />
	<link rel="stylesheet" th:href="@{/weixin/css/weui.min.css}" />
    <script type="text/javascript"  th:src="@{/weixin/js/adaptive.js}"></script>
	<script type="text/javascript"  th:src="@{/weixin/js/fastclick.min.js}"></script>
	<script type="text/javascript"  th:src="@{/weixin/js/zepto.min.js}"></script>
	<script type="text/javascript"  th:src="@{/weixin/js/dropload.min.js}"></script>
	<script type="text/javascript" th:src="@{/weixin/js/weui.min.js}"></script>
	<script type="text/javascript" th:src="@{/assets/js/plugins/moment/moment.js}"></script>
	<style>
	.noneBorder{
		border: none;
	}
	body{font-size: initial !important;}
	</style>
</head>
<body>
	<section class="recordBox wrapper">
		
		<div class="box-h recordDate">
			<ul class="dataList flex">
				<li class="box-h">
					<span class="name">开始时间</span>
					<p id="beginDate" class="date flex" th:text="${beginDate}"></p>
					<!-- <input type="text" class="noneBorder" id="beginDate" readonly="readonly" /> -->
				</li>
				<li class="box-h">
					<span class="name">结束时间</span>
					<p id="endDate" class="date flex" th:text="${endDate}"></p>
					<!-- <input type="text" class="noneBorder" id="endDate" readonly="readonly" /> -->
				</li>
			</ul>
			<a th:if="${!#strings.isEmpty(distributorId)}" href="javascript:toHref(1, '');" class="btn">确定</a>
			<a th:if="${!#strings.isEmpty(customerId)}" href="javascript:toHref2();" class="btn">确定</a>
		</div>
	
		<p class="comTab box-h" th:if="${!#strings.isEmpty(distributorId)}">
			<a id="menu-1" onclick="toHref(1)" class="flex">消费记录</a>
			<a id="menu-2" onclick="toHref(2)"  class="flex">K记录</a>
			<a id="menu-3" onclick="toHref(3, 0)"  class="flex">结算记录</a>
		</p>
		<ul class="list">
			
		</ul>
		
		<div class="ktab" th:if="${!#strings.isEmpty(customerId)}">
			<table>
				<thead>
					<tr>
						<td>姓名</td>
						<td>日期</td>
						<td>金额</td>
					</tr>
				</thead>
				<tbody id="context">
				</tbody>
			</table>
		</div>
	</section>
	
	<input id="customerId" th:value="${customerId}" type="hidden"/>
</body>
<script  th:inline="JavaScript">
    var query = {'customerId':[[${customerId}]],'distributorId':[[${distributorId}]],'isBalance':[[${isBalance}]],'beginDate':[[${beginDate}]],'endDate':[[${endDate}]]};
    var menu = /*[[${menu}]]*/;
    
</script>
<script type="text/javascript">
/*<![CDATA[*/
     
     function toHref2(){
    	
		var listUrl = "/qianjun/weixin/order/tolist?customerId=" + $("#customerId").val();	
			
    	var beginDate = $("#beginDate").text();
    	var endDate = $("#endDate").text();
    	
    	if(beginDate){
    		listUrl += "&beginDate=" + beginDate;
    	}
    	
    	if(endDate){
    		listUrl += "&endDate=" + endDate;
    	}	
    	
    	window.location.href = listUrl;
    }      
           
     function toHref(menuId, isBalance){
    	
		var listUrl = "/qianjun/weixin/order/tolist?menu=" + menuId + "&distributorId=" + query.distributorId;	
			
		if(isBalance != '' && isBalance != undefined){
    		listUrl += "&isBalance=" + isBalance;
    	}
    	
    	var beginDate = $("#beginDate").text();
    	var endDate = $("#endDate").text();
    	
    	if(beginDate){
    		listUrl += "&beginDate=" + beginDate;
    	}
    	
    	if(endDate){
    		listUrl += "&endDate=" + endDate;
    	}	
    	
    	window.location.href = listUrl;
    }
           
$(function(){
	
	$("#beginDate").click(function(){
		weui.datePicker({
			start: '2017-07-01',
			end: moment().add(30,"days").format("YYYY-MM-DD"),
	        onConfirm: function onConfirm(result) {
	        	
	        	var d = result[0].value + "-" + (result[1].value < 10 ? ("0" + result[1].value) : result[1].value) + "-" + (result[2].value < 10 ? ("0" + result[2].value) : result[2].value);
	        	
	        	//$("#date").val(moment(d).format("YYYY-MM-DD"));
	        	$("#beginDate").text(d);
	        	query["beginDate"] = d;
	        },
	        id: 'datePicker'
	    });
	});
	
	$("#endDate").click(function(){
		weui.datePicker({
	        start: '2017-07-01',
	        end: moment().add(30,"days").format("YYYY-MM-DD"),
	        onConfirm: function onConfirm(result) {
	        	var d = result[0].value + "-" + (result[1].value < 10 ? ("0" + result[1].value) : result[1].value) + "-" + (result[2].value < 10 ? ("0" + result[2].value) : result[2].value);
	        	//$("#date").val(moment(d).format("YYYY-MM-DD"));
	        	$("#endDate").text(d);
	        	query["endDate"] = d;
	        },
	        id: 'datePicker'
	    });
	});
	
	menu = menu == null ? '1' : menu;
	$("#menu-"+menu).addClass("curr");
	
	page = 0;
    $('.wrapper').dropload({
	    //scrollArea : window,
	    autoLoad : true,//自动加载
	    loadDownFn : function(me){
	      window.history.pushState(null, document.title, window.location.href); 
	      var queryUrl = '';
	      
	      if(menu != 2){
	    	  queryUrl = '/qianjun/weixin/order/list?page='+ page;
	      } else{
	    	  queryUrl = "/qianjun/weixin/rebate/rebateBook/list?page=" + page;
	    	  query['type'] = 0;
	      }
	      
	        $.ajax({
	            type: 'GET',
	            url: queryUrl,
	            dataType: 'json',
	            data: query,
	            success: function(data){
	                if(data.content.length == 0){
	                    me.lock();
	                    me.noData();
	                    me.resetload();
	                    return;
	                }

			        var result = '';
	                for(var i=0; i< data.content.length; i++){
	                  result+=content(data.content[i]);
	                }
	                
	                if($("#customerId").val()){
	                	$('#context').append(result);
	                }else{
	                	$('.list').append(result);	
	                }
	                
	                page++;
	                me.resetload();
	            },
	            error: function(xhr, type){
	                me.resetload();
	            }
	        });
	    }
	});
});

function content(data){
	var name = '';
	var amount = '';
	if(menu == 1){
		name = data.projectName;
		amount = data.amount;
	}else if(menu == 2){
		name = data.rebateReason;
		amount = data.rebate;
	}else if(menu == 3){
		name = data.projectName;
		amount = data.distributorRebate;
	}
	
	
	var html = '';
	if($("#customerId").val()){
		html = "<tr><td>" + data.customerName + "</td><td>" + data.createTime + "</td><td>" + amount + "</td></tr>"
		html += '<tr class="des"><td colspan="3">美容项目</td></tr>';
	}else{
		html =  '<li><p class="name">'+name+'</p><time>'+data.createTime+'</time>';
		html += '<i class="num">'+amount+'</i></li>';
	}
	return html;
}


/*]]>*/
</script>
</html>